GetSchoolVouchersQueryHandler.execute   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 16
rs 9.75
c 0
b 0
f 0
cc 2
1
import { QueryHandler } from '@nestjs/cqrs';
2
import { Inject } from '@nestjs/common';
3
import { GetSchoolVouchersQuery } from './GetSchoolVouchersQuery';
4
import { IVoucherRepository } from 'src/Domain/School/Repository/IVoucherRepository';
5
import { SchoolUserView } from '../../View/SchoolUserView';
6
7
@QueryHandler(GetSchoolVouchersQuery)
8
export class GetSchoolVouchersQueryHandler {
9
  constructor(
10
    @Inject('IVoucherRepository')
11
    private readonly voucherRepository: IVoucherRepository
12
  ) {}
13
14
  public async execute(query: GetSchoolVouchersQuery): Promise<SchoolUserView[]> {
15
    const schoolUserViews: SchoolUserView[] = [];
16
    const vouchers = await this.voucherRepository.findBySchool(query.schoolId);
17
18
    for (const voucher of vouchers) {
19
      schoolUserViews.push(
20
        new SchoolUserView(
21
          voucher.getId(),
22
          voucher.getEmail(),
23
          'voucher'
24
        )
25
      );
26
    }
27
28
    return schoolUserViews;
29
  }
30
}
31